import java.util.HashMap;
import java.util.Map;

public class Q2 {

    public int[] indexs(int[] nums, int target) {
        // 创造一个map
        Map<Integer, Integer> indexes = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            indexes.put(nums[i], i);
        }
        for (int i = 0; i < nums.length-1; i++) {
            int remain = target - nums[i];
            final Integer integer = indexes.get(remain);
            if (integer != null && integer != i) {
                return new int[]{i, integer};
            }
        }
        return null;
    }

    public static void main(String[] args) {
        int[] i = new int[]{2,1,4,3,9,5};
        final int[] indexs = new Q2().indexs(i, 4);
        for (int index : indexs) {
            System.out.println(index);
        }
    }

}
